Default Crosswalk Rule defining a crosswalk conversion.
When a crosswalk is loaded each line in the crosswalk file is turned into a rule. For this default rule the initial value is the key in the crosswalk and the result is the value in the crosswalk. See crosswalk for more details.
Public Methods: handle – Returns true if initial matches the value convert – Returns the result
Crosswalk rule to handle all values. If result is :copy: will copy the initial value to the result value, otherwise will output the result value.
example) :all: :copy: This will output exactly what is in the original dataset without doing any conversion.
| All: |
|
|---|
This will output a None value.
| All: | 1111.11 |
|---|
This will output all values to 1111.11
A Crosswalk object is used to do variable conversions either directly or by accessing the object in the func.py file for a CCHR variable.
The Crosswalk object first loads the crosswalk.txt file specified by the filename parameter. Each line of this file is turned into a rule object, see _rules for more information. When crosswalk.convert(value) is called we iterate over the rules list checking to see if a rule can handle the value. If a rule can handle the value the rules result is returned, otherwise we raise a ConvertError. An additional lookup parameter can be defined to provide a list of valid return values.
The column delimiter is a tab and the row delimiter is a newline. So each line in the crosswalk looks like:
keyt**value**n
example)
100 murder
parameters:
filename - Path to file containing crosswalk information. lookup - A list of valid values that can be returned by the convert function.
Returns a converted value based on key or raises a ConvertError if key can not be converted.
Looks to see if there is a rule that can handle a given key. Split keyword returns the converted result as a list of values, using the value of the split keyword as the delimiter for the result list.
Transform the given key by applying the rules in the crosswalk. If a rule can handle the key it will remove the matched text from the key. After the rules are applied the transformed key will be returned.
The optional argument of count is the maximum number of times a transform will be applied to the key. By default (count=0) all rules will be checked to see if they can handle the key. If count is specified than the crosswalk will incrememnt a counter for each time a rule handles the key. Once the counter = count the crosswalk will return the transformed key.